<?php

/**
 * HorarioCurso form.
 *
 * @package    ecampus
 * @subpackage form
 * @author     Grupo 608
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class HorarioCursoForm extends BaseHorarioCursoForm
{
  public function configure()
  {
      $horarioEscolar = array(6, 7, 8, 9, 10, 11, 12, 13, 14 ); //, 15, 16, 17);
      $minutos = array(00, 15, 30, 45);

      $this->widgetSchema['dia'] = new sfWidgetFormChoice(array(
          'choices' => HorarioCurso::getDias(),
          'expanded' => false,
          'label' => 'Dia',
          'default' => null
       ));
      $this->validatorSchema['dia']->setOption('required', false);

      $this->widgetSchema['hora_desde'] = new sfWidgetFormTime(array(
          'hours' => array_combine($horarioEscolar, $horarioEscolar) ,
          'minutes' => array_combine($minutos, $minutos)
      ));
      $this->validatorSchema['hora_desde']->setOption('required', false);

      $this->widgetSchema['hora_hasta'] = new sfWidgetFormTime(array(
          'hours' => array_combine($horarioEscolar, $horarioEscolar) ,
          'minutes' => array_combine($minutos, $minutos)
      ));
      $this->validatorSchema['hora_hasta']->setOption('required', false);

      //validacion hora_desde < hora_hasta
      $this->validatorSchema->setPostValidator(
                new sfValidatorSchemaCompare('hora_desde',
                        sfValidatorSchemaCompare::LESS_THAN_EQUAL,
                        'hora_hasta',
                        array(),
                        array('invalid' => 'La hora de inicio (%left_field%) debe ser menor a la de finalizacion (%right_field%)'))
          );
//  $this->validatorSchema->setPostValidator(
//      new sfValidatorCallback(array('callback' => array($this, 'checkPassword')))
//    );
//      $this->PostValidator( new HorarioCursoValidatorSchema() );
  }
   public function checkPassword($validator, $values)
      {
    if ($values['dia'] == 1  )
    {
      // password is not correct, throw an error
      throw new sfValidatorError($validator, 'Invalid password');
    }

    // password is correct, return the clean values
    return $values;
  }
}
